package com.handsome.原型模式.浅拷贝深拷贝;


import java.io.Serializable;
import java.util.Date;

/**
 * 使用clone方法实现深拷贝
 *
 * @author niechun
 * @date 2023/1/17 21:05
 */
public class DeepSheep implements Cloneable, Serializable {
    private String name;

    private int age;

    private Date date;

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    protected DeepSheep clone() throws CloneNotSupportedException {
        DeepSheep sheep = (DeepSheep) super.clone();
        sheep.setDate(new Date());
        return sheep;
    }

    @Override
    public String toString() {
        return "Sheep{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
